<?php

class OrderDetailTest extends BaseTest
{
    public function testInsert()
    {
        $class = new \Orm\OrderDetail\OrderDetailClass();
		$class['order_id'] = $this->testNum();
		$class['product_id'] = $this->testNum();
		$class['unit_price'] = $this->testNum();
		$class['amount'] = $this->testNum();
		$class['total_price'] = $this->testNum();


        $class->insert();
        $result_class = new \Orm\OrderDetail\OrderDetailClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['order_id'],$result_class['order_id']);
		$this->assertEquals($class['product_id'],$result_class['product_id']);
		$this->assertEquals($class['unit_price'],$result_class['unit_price']);
		$this->assertEquals($class['amount'],$result_class['amount']);
		$this->assertEquals($class['total_price'],$result_class['total_price']);

        return $result_class;
    }

    /**
     * @depends testInsert
     */
    public function testUpdate($class)
    {
		$class['order_id'] = $this->testNum();
		$class['product_id'] = $this->testNum();
		$class['unit_price'] = $this->testNum();
		$class['amount'] = $this->testNum();
		$class['total_price'] = $this->testNum();


        $class->update();
        $result_class = new \Orm\OrderDetail\OrderDetailClass();
        $result_class->loadById($class['id']);

		$this->assertEquals($class['order_id'],$result_class['order_id']);
		$this->assertEquals($class['product_id'],$result_class['product_id']);
		$this->assertEquals($class['unit_price'],$result_class['unit_price']);
		$this->assertEquals($class['amount'],$result_class['amount']);
		$this->assertEquals($class['total_price'],$result_class['total_price']);

        return $result_class;
    }

    /**
     * @depends testUpdate
     */

    public function testDelete($class)
    {
        $class->delete($class['id']);

        $result_class = new \Orm\OrderDetail\OrderDetailClass();
        $result_class->loadById($class['id']);
        $this->assertEquals(1, $result_class['is_del']);
        return $result_class;
    }


    /**
     * @depends testInsert
     */
    public static function testClean($class)
    {
        if ($class['id']) {
            $class->realDelete($class['id']);
        }
    }
}